#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

int minNumberOfFrogs(string croakOfFrogs) {
    const string croak = "croakc";
    char prev['s'];
    for (int i = 1; i < croak.size(); i++)
        prev[croak[i]] = croak[i - 1];

    int cnt['s'];
    for (auto c : croakOfFrogs)
    {
        char pre = prev[c];
        if (cnt[pre])
            cnt[pre]--;
        else if (c != 'c')
            return -1;
        cnt[c]++;
    }
    if (cnt['c'] || cnt['r'] || cnt['o'] || cnt['a'])
        return -1;
    return cnt['k'];
}